//go:build linux || darwin

package controller

import (
	"fmt"
	"os"
	"strings"
	"time"
)

type Wallpaper struct {
	Base
}

func NewWallpaper() *Wallpaper {
	return &Wallpaper{}
}

// SetBackGround 下载远程图片并设置成壁纸
func (w *Wallpaper) SetBackGround(url string) {
	//获取壁纸保存名称
	path := w.pathExist(fmt.Sprintf("%s/wallpapers", w.getAppPath()))
	split := strings.Split(url, ".")
	ext := split[len(split)-1]
	filename := fmt.Sprintf("%s/%d.%s", path, time.Now().Unix(), ext)

	//下载
	_ = os.WriteFile(filename, w.httpGet(url), os.ModePerm)

	//设置壁纸
	w.setSystemBackground(filename)
}
